﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.materialbasicinfo
{
    public partial class Modify : Web.Admin.BasePage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lcs.BLL.materialtypeinfo bm = new BLL.materialtypeinfo();
                ddltype.DataSource = bm.GetAllList().Tables[0];
                ddltype.DataTextField = "mtname";
                ddltype.DataValueField = "mtid";
                ddltype.DataBind();
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int mbid = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(mbid);
                }
            }
        }

        private void ShowInfo(int mbid)
        {
            lcs.BLL.materialbasicinfo bll = new lcs.BLL.materialbasicinfo();
            lcs.Model.materialbasicinfo model = bll.GetModel(mbid);
            this.lblmbid.Text = model.mbid.ToString();
            this.txtmbm.Text = model.mbm;
            this.txtmms.Text = model.mms;
            this.txtmunit.Text = model.munit;
            ddltype.SelectedValue = model.mtype.ToString();
            this.txtmark1.Text = model.mark1;
            this.txtmark2.Text = model.mark2;
            this.txtmark3.Text = model.mark3;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtmbm.Text.Trim().Length == 0)
            {
                strErr += "物料编码不能为空！\\n";
            }
            if (this.txtmms.Text.Trim().Length == 0)
            {
                strErr += "物料描述不能为空！\\n";
            }
            if (this.txtmunit.Text.Trim().Length == 0)
            {
                strErr += "计量单位不能为空！\\n";
            }           
            
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int mbid = int.Parse(this.lblmbid.Text);
            string mbm = this.txtmbm.Text;
            string mms = this.txtmms.Text;
            string munit = this.txtmunit.Text;
            int mtype = int.Parse(this.ddltype.SelectedValue.ToString());
            string mark1 = this.txtmark1.Text;
            string mark2 = this.txtmark2.Text;
            string mark3 = this.txtmark3.Text;


            lcs.Model.materialbasicinfo model = new lcs.Model.materialbasicinfo();
            model.mbid = mbid;
            model.mbm = mbm;
            model.mms = mms;
            model.munit = munit;
            model.mtype = mtype;
            model.mark1 = mark1;
            model.mark2 = mark2;
            model.mark3 = mark3;

            lcs.BLL.materialbasicinfo bll = new lcs.BLL.materialbasicinfo();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "List.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}
